package com.itheima.user.web;

import com.itheima.user.config.JdbcProperties;
import com.itheima.user.domain.User;
import com.itheima.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
//@RefreshScope //热更新
public class UserController {

    @Autowired
    private UserService userService;


    @GetMapping("/{id}")
    public User findById(@PathVariable("id") Long id) {
        return userService.findById(id);
    }

    @Value("${jdbc.username}")
    String username;

    @Value("${jdbc.password}")
    String password;

//    @GetMapping("config")
//    public String getJdbcConfig(){
//        return  username+"@"+password;
//    }
    @Autowired
    JdbcProperties jdbcProperties;

    @GetMapping("config2")
    public String getJdbcConfig2(){
        return  jdbcProperties.getUsername()+"@"+jdbcProperties.getPassword();
    }

}
